package com.xquant.pricing.pricingConfig.controller;

import com.github.pagehelper.PageInfo;
import com.xquant.common.security.annotation.RequiresPermissions;
import com.xquant.pricing.pricingConfig.service.TargetParamService;
import com.xquant.pricing.utils.CacheUtil;
import com.xquant.pricing.utils.CommResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * @Auther: newCould
 * @Date: 01/03/2022 15:22
 * @Description: newCloud Controller  标的参数配置管理
 */
@RestController
@RequestMapping("targetParamController")
public class TargetParamController {


    @Autowired
    private TargetParamService targetParamService;

    /**
     * 查询 标的参数配置
     */
    @RequestMapping(value = "/queryTargetParamCfgByPage.action")
    public PageInfo<Map> queryTargetParamCfgByPage(@RequestParam Map<String, Object> param) {

        PageInfo<Map> pageInfo = targetParamService.queryTargetParamCfgByPage(param);

        return pageInfo;
    }
    /**
     * 查询 标的参数配置
     */
    @RequestMapping(value = "/queryTargetParamCfg.action")
    public PageInfo<Map> queryTargetParamCfg(@RequestParam Map<String, Object> param) {

        PageInfo<Map> pageInfo = targetParamService.queryTargetParamCfg(param);

        return pageInfo;
    }


    /**
     * 新增
     */
    @RequiresPermissions("pricingconfig:otcoption:targetadd")
    @RequestMapping(value = "/insertTargetParamCfg.action")
    public Object insertTargetParamCfg(@RequestParam Map<String, Object> param) {
        List<Map> list = targetParamService.queryTargetParamCfg(param).getList();
        if (list.size() == 0) {
            CacheUtil.getInstance().removeAllCacheData();
            targetParamService.insertTargetParamCfg(param);
        } else {
            return CommResponse.failure("配置已存在，保存失败");
        }
        return CommResponse.success("保存成功");
    }
    /**
     * 修改
     */
    @RequiresPermissions("pricingconfig:otcoption:targetedit")
    @RequestMapping(value = "/updateTargetParamCfg.action")
    public Object updateTargetParamCfg(@RequestParam Map<String, Object> param) {
        List<Map> list = targetParamService.queryTargetParamCfg(param).getList();
        if (list.size() == 0) {
            return CommResponse.failure("更新失败");
        } else {
            CacheUtil.getInstance().removeAllCacheData();
            targetParamService.updateTargetParamCfg(param);
        }
        return CommResponse.success("更新成功");
    }

    /**
     * 删除
     */
    @RequiresPermissions("pricingconfig:otcoption:targetremove")
    @RequestMapping(value = "/deleteTargetParamCfg.action")
    public Object deleteTargetParamCfg(@RequestParam Map<String, Object> param) {

        targetParamService.deleteTargetParamCfg(param);
        CacheUtil.getInstance().removeAllCacheData();
        return CommResponse.success("保存成功");
    }


}
